home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / monax25 / repraw.c < prev    next >
Text File  |  1987-10-18  |  8KB  |  299 lines

  1. /* repraw.c - format raw log repords for display.
  2.    This module is part of report.exe
  3.                   
  4.    Language = Microsoft C version 4.0
  5.  
  6.  
  7.    This source is distributed freely and may be copied and
  8.    redistributed with the following provisos:
  9.    
  10.            You may not sell it, nor may you charge for making 
  11.            copies beyond the actual cost of mailing and media.
  12.                       
  13.    Written by Skip Hansen WB6YMH and Harold Price NK6K.
  14.  
  15.    Feedback is desired.
  16.  
  17.    RCP/M (213) 541-2503 300/1200/2400 baud
  18.    or via packet WB6YMH @ WB6YMH-2 or 
  19.          NK6K @ NK6K
  20.  
  21.    Modification history:
  22.  
  23.     8/10/87         NK6K: Initial release.    
  24.     ver 1.0         
  25.  
  26.    10/18/87     NK6K: First general release.
  27.    ver 1.1
  28. */
  29. /* repraw - raw record dump */
  30. #define LINT_ARGS
  31. #include "monfile.h"
  32. #include <stdio.h>
  33. #include <memory.h>
  34. struct CIRCUIT_RECORD crec;
  35. struct DIGI_RECORD drec;
  36. struct FREQ_RECORD frec;
  37. struct TIME_RECORD trec;
  38. struct ID_RECORD irec;
  39. struct FREQ_RECORD t_frec;
  40.  
  41. extern char sel_types[0];
  42. extern FILE *fin,*fout;
  43. extern char sel_call[11];
  44. extern int sel_flag;
  45. extern unsigned long recnum;
  46.  
  47. char fbuf[257];
  48.  
  49. long first_timestamp=0;
  50. long last_timestamp=0; 
  51.  
  52. char *getrec(buf,size,file)
  53. char *buf;
  54. int size;
  55. FILE *file;
  56. {
  57. char test[2];
  58. char tbuf[30];
  59.  
  60.     while (1) {
  61.         if (fgets(buf,size,file)==NULL) return(NULL);
  62.         recnum++;
  63.         test[1]='\0';
  64.         test[0]=toupper(buf[0]);        
  65.         if (test[0]=='T') {
  66.             if (first_timestamp==0) 
  67.                 sscanf(fbuf+2,"%lu",&first_timestamp);
  68.             sscanf(fbuf+2,"%lu",&last_timestamp);    
  69.             }
  70.  
  71.         if (strpbrk(sel_types,test)!=NULL) {
  72.             if (! sel_flag) break;
  73.             if (buf[0]!='C') break;
  74.             strncpy(tbuf,buf,30);
  75.             if (strcmp(strtok(tbuf+2,","),sel_call)==0) break;
  76.             if (strcmp(strtok(NULL,","),sel_call)==0) break;
  77.             }
  78.         }
  79.     return(buf);
  80. }
  81.  
  82. report_raw(flag)
  83. int flag;        /* set if only totals are desired */
  84. {
  85. int tmp;
  86. unsigned long tmpl;
  87. float tmpf;
  88. char otype;
  89.     
  90.      otype='\0';
  91.      first_timestamp=0;
  92.      memset((char *)&t_frec,'\0',sizeof(t_frec));
  93.      while(1) {
  94.     if (getrec(fbuf,256,fin)==NULL) break;
  95.     if (kbhit()) break;
  96.     switch (fbuf[0]) {
  97.     case TIME_TYPE:
  98.         if (flag) break;
  99.         tmp=sscanf(fbuf+2,"%lu",&trec.time_stamp);    
  100.         if (tmp==1) {
  101.             fprintf(fout,"\nTime Stamp %s\n",ctime(&trec.time_stamp));
  102.             }
  103.         else cprintf("*** bad Time rec, number %lu ***\r\n",recnum);
  104.         break;
  105.  
  106.     case FREQ_TYPE:
  107.         tmp=sscanf(fbuf+2,"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu",
  108.             &frec.t_packets,
  109.             &frec.t_bytes,
  110.             &frec.u_packets,
  111.             &frec.u_bytes,
  112.             &frec.l32,
  113.             &frec.l64,
  114.             &frec.l128,
  115.             &frec.l256,
  116.             &frec.g256,
  117.             &frec.dcd_on_ticks,
  118.             &frec.dcd_off_ticks);
  119.  
  120.         if (tmp!=11) {
  121.             cprintf("*** bad Freq rec, number %lu ***\r\n",recnum); 
  122.             break;
  123.             }
  124.         t_frec.t_packets+=frec.t_packets;
  125.         t_frec.t_bytes+=frec.t_bytes;
  126.         t_frec.u_packets+=frec.u_packets;
  127.         t_frec.u_bytes+=frec.u_bytes;
  128.         t_frec.l32+=frec.l32;
  129.         t_frec.l64+=frec.l64;
  130.         t_frec.l128+=frec.l128;
  131.         t_frec.l256+=frec.l256;
  132.         t_frec.g256+=frec.g256;
  133.         t_frec.dcd_on_ticks+=frec.dcd_on_ticks;
  134.         t_frec.dcd_off_ticks+=frec.dcd_off_ticks;
  135.  
  136.         if (flag) break;    /* totals only */
  137.  
  138.         tmpf= frec.l32+frec.l64+frec.l128+frec.l256+frec.g256;
  139.         if (tmpf==0.0) tmpf=1.0;
  140.         if (otype!=FREQ_TYPE) {
  141.             fprintf(fout,
  142. "F Total    Total    Unique   Unique   %%DCD   %%<32  <64   <128  <256  >256\n");
  143.             fprintf(fout,
  144. "  Packets  Bytes    Packets  Bytes     ON \n"); 
  145.             }
  146.         fprintf(fout,"  %-7lu  %-7lu  %-7lu  %-7lu  %-7.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f\n",
  147.             frec.t_packets,
  148.             frec.t_bytes,
  149.             frec.u_packets,
  150.             frec.u_bytes,
  151.             (float) ((float) frec.dcd_on_ticks /    
  152.               (float) (frec.dcd_on_ticks+frec.dcd_off_ticks)) * 100.0,
  153.  
  154.             100.0 * (((float) frec.l32)/tmpf),
  155.             100.0 * (((float) frec.l64)/tmpf),
  156.             100.0 * (((float) frec.l128)/tmpf),
  157.             100.0 * (((float) frec.l256)/tmpf),
  158.             100.0 * (((float) frec.g256)/tmpf)
  159.             );
  160.  
  161.         break;
  162.  
  163.  
  164.     case DIGI_TYPE:
  165.         tmp = sscanf(fbuf+2,"%[^,],%lu,%lu",drec.call,&drec.t_packets,
  166.             &drec.t_bytes);
  167.         if (tmp!=3) {
  168.             cprintf("*** bad Digi rec, number %lu ***\r\n",recnum); 
  169.             break;
  170.             }
  171.         if (flag) break;
  172.         if (otype!=DIGI_TYPE) 
  173.             fprintf(fout,"\nD Call        Total Packets   Total Bytes\n");
  174.  
  175.         fprintf(fout,"  %-10s  %-9lu       %-9lu\n",
  176.             drec.call,
  177.             drec.t_packets,
  178.             drec.t_bytes);     
  179.         break;
  180.  
  181.     case CIRCUIT_TYPE:
  182.         tmp = sscanf(fbuf+2,
  183. "%[^,],%[^,],%u,%u,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,\
  184. %lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu",
  185.         crec.to,        
  186.         crec.from,        
  187.         &crec.digis,        
  188.         &crec.pid,
  189.         &crec.u_dpackets,    
  190.         &crec.nd_dpackets,    
  191.         &crec.t_dpackets,    
  192.         &crec.nd_packets,    
  193.         &crec.t_packets,    
  194.         &crec.u_dbytes,        
  195.         &crec.nd_dbytes,    
  196.         &crec.t_dbytes,        
  197.         &crec.nd_bytes,        
  198.         &crec.t_bytes,        
  199.         &crec.c_time,        
  200.         &crec.sabm,
  201.         &crec.ua,
  202.         &crec.disc,
  203.         &crec.dm,
  204.         &crec.rej,
  205.         &crec.rr,
  206.         &crec.rnr,
  207.         &crec.i,
  208.         &crec.ui,
  209.         &crec.frmr,
  210.         &crec.poll,
  211.         &crec.final,
  212.         &crec.l32,    
  213.         &crec.l64,    
  214.         &crec.l128,
  215.         &crec.l256,
  216.         &crec.g256);
  217.  
  218.         if (tmp!=32) {
  219.             cprintf("*** bad Circuit rec, number %lu ***\r\n",recnum); 
  220.             break;
  221.             }
  222.         /*n* total */
  223.  
  224.         if (flag) break;
  225.         
  226.         fprintf(fout,"%-10s > %-10s  ",crec.from, crec.to);
  227.             fprintf(fout,
  228.         "------- I frames --------  ------ All frames -------\n");
  229.             fprintf(fout,
  230. "             %-10lu  Total    NotDigi  Unique   Total    NotDigi  \n",recnum);
  231.             fprintf(fout,
  232. "                         Packets  Packets  Packets  Packets  Packets\n");
  233.             fprintf(fout,
  234. "                         Bytes    Bytes    Bytes    Bytes    Bytes\n\n");
  235.         fprintf(fout,"                         %-7lu  %-7lu  %-7lu  %-7lu  %-7lu\n",
  236.             crec.t_dpackets,crec.nd_dpackets,crec.u_dpackets,
  237.             crec.t_packets,crec.nd_packets);
  238.         fprintf(fout,"                         %-7lu  %-7lu  %-7lu  %-7lu  %-7lu\n\n",
  239.             crec.t_dbytes,crec.nd_dbytes,crec.u_dbytes,
  240.             crec.t_bytes,crec.nd_bytes);
  241.         fprintf(fout,
  242. "                         sabm     ua       disc     dm       rej      rr\n");
  243.         fprintf(fout,"                         %-7lu  %-7lu  %-7lu  %-7lu  %-7lu  %-7lu\n\n",
  244.             crec.sabm,crec.ua,crec.disc,crec.dm,crec.rej,crec.rr);
  245.         fprintf(fout,
  246. "                         rnr      i        ui       frmr    poll      final\n");
  247.         fprintf(fout,"                         %-7lu  %-7lu  %-7lu  %-7lu  %-7lu  %-7lu\n\n",
  248.             crec.rnr,crec.i,crec.ui,crec.frmr,crec.poll,crec.final);
  249.         fprintf(fout,    
  250. "                         ndigi    <32      <64      <128    <256      >256\n");
  251.         fprintf(fout,"                         %-7u  %-7.lu  %-7.lu  %-7.lu  %-7.lu  %-7.lu\n\n",
  252.             crec.digis,crec.l32,crec.l64,crec.l128,crec.l256,crec.g256);
  253.         break;
  254.  
  255.  
  256.  
  257.         }
  258.     otype = fbuf[0];
  259.   }
  260.  
  261.     if (kbhit()) {
  262.         getch();
  263.         return;
  264.         }
  265.     if (strchr(sel_types,'T')!=NULL) {
  266.         fprintf(fout,"Totals:  Start time %24.24s\n",ctime(&first_timestamp));
  267.         fprintf(fout,"         End time   %24.24s\n",ctime(&last_timestamp));
  268.         tmpl=last_timestamp-first_timestamp;
  269.         fprintf(fout,"         %u hr  %u min\n", (unsigned int) (tmpl/3600l),
  270.             (unsigned int) (tmpl % 3600l)/60l);
  271.         }
  272.  
  273.     tmpf= t_frec.l32+t_frec.l64+t_frec.l128+t_frec.l256+t_frec.g256;
  274.  
  275.         if ((strchr(sel_types,'F')!=NULL) && (tmpf !=0.0 )){
  276.             fprintf(fout,
  277. "F Total    Total    Unique   Unique   %%DCD   %%<32  <64   <128  <256  >256\n");
  278.             fprintf(fout,
  279. "  Packets  Bytes    Packets  Bytes     ON \n"); 
  280.         fprintf(fout,"  %-7lu  %-7lu  %-7lu  %-7lu  %-7.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f\n",
  281.             t_frec.t_packets,
  282.             t_frec.t_bytes,
  283.             t_frec.u_packets,
  284.             t_frec.u_bytes,
  285.             (float) ((float) t_frec.dcd_on_ticks /    
  286.               (float) (t_frec.dcd_on_ticks+t_frec.dcd_off_ticks)) * 100.0,
  287.  
  288.             100.0 * (((float) t_frec.l32)/tmpf),
  289.             100.0 * (((float) t_frec.l64)/tmpf),
  290.             100.0 * (((float) t_frec.l128)/tmpf),
  291.             100.0 * (((float) t_frec.l256)/tmpf),
  292.             100.0 * (((float) t_frec.g256)/tmpf)
  293.             );
  294.  
  295.         }
  296.  
  297. }
  298.             
  299.